// 用于主页面通用内容
import Main from '@/views/main.vue';
// 用于加载三级路由内容
import RouterView from '@/views/router-view.vue';

/*
 * meta 参数说明
 * @params	string	title	页面标题
 * @params	boolean	cache	是否通过router-view的keep-alive缓存页面
 * @params	boolean access	权限，需自行写相关业务逻辑
 * 
 */

/*
 * unLoginRouter 说明
 * 1.未登录状态下可访问的独立页面
 * 
 */
export const unLoginRouter = [
	{
        path: '/login',
        name: 'login',
        meta: {
            title: '登录'	
        },
        component: resolve => {
        	require(['@/views/login/login.vue'], resolve)
        }
    }
]

/*
 * simpleRouter 简单路由说明
 * 1.登录状态下可访问的独立页面
 * 
 */
export const simpleRouter = [
	{
		path: '/404',
		name: 'error-404',
		meta: {
			title: '404 页面不存在'
		},
		component: resolve => {
			require(['@/views/error/404.vue'], resolve)
		}
	}
]

/*
 * mainRouter 说明
 * 1.需登录后才可访问的路由
 * 2.需要通过main通用组件显示的路由
 * 3.不需要在主菜单显示的路由
 * 
 */
export const mainRouter = {
	path: '/',
	name: 'mainRouter',
	redirect: '/home',		// 将/重置到/home主页
	component: Main,
	children: [
		{
    		path: 'user/detail',
        	name: 'user_detail',
        	meta: {
        		title: '用户详情'
        	},
        	component: resolve => {
	        	require(['@/views/user/detail.vue'], resolve)
	        }
    	}
	]
}

/*
 * appRouter 说明
 * 1.需登录后才可访问的路由
 * 2.需要通过main通用组件显示的路由
 * 3.需要展示在主菜单里的路由，支持多级，3级及以上的路由需要通过RouterView来加载
 * 
 */
export const appRouter = [
	// 如果首页不需要展示在主菜单里，可放在mainRouter里
	{
		path: '/home',
		name: 'home',
		redirect: '/home/index',
		meta: {
			title: '首页'
		},
        component: Main,
        children: [
        	{
        		path: 'index',
	        	name: 'home_index',
	        	meta: {
	        		title: '首页',
					cache: true
	        	},
	        	component: resolve => {
		        	require(['@/views/home/index.vue'], resolve)
		        }
        	}
        ]
	},
	{
		path: '/user',
		name: 'user',
		redirect: '/user/list',
		meta: {
			title: '用户'
		},
        component: Main,
        children: [
        	{
        		path: 'list',
	        	name: 'user_list',
	        	meta: {
	        		title: '用户列表',
					cache: true
	        	},
	        	component: resolve => {
		        	require(['@/views/user/list.vue'], resolve)
		        }
        	}
        ]
	}
]

// 所有上面定义的路由都要写在下面的routers里
export const routers = [
	...unLoginRouter,
    ...simpleRouter,
    ...appRouter,
    mainRouter
];